<?php
require_once('db/db.php');
$db=new DB;

$first_step=8;

function get_product($ca, $start, $step){
	global $db;
	$category=intval($ca);
	if($category<=0){
		$sql="select * from product order by click_counts desc limit $start,$step";
		$result=$db->get_all($sql);
	}
	else {
	   $id_set=array($category);
 	   $child_set=$db->get_all("select id from category where father=$category");
 	   foreach($child_set as $value)
 	       array_push($id_set, $value['id']);
 	   $id_str=implode(',', $id_set);
 	   $sql="select * from product where category in ($id_str) order by click_counts desc limit $start,$step";
 	   $result=$db->get_all($sql);
	}
	foreach($result as $item){
	    $name=$item['name'];
	    $pic_link=$item['pic_link'];
	    $prime_price=$item['prime_price'];
	    $price=$item['price'];
	    $desc=$item['desc'];
	    $product_link=$item['product_link'];
	    $click_counts=$item['click_counts'];
	    $id=$item['id'];
	    echo "
	    <div class=\"col\">
	    <a class=\"product_img\" href=\"$product_link\" target=\"_blank\" onclick=\"counts($id);\" >
	    <img src=\"$pic_link\" alt=\"$name\" />
	    </a><hr />
		<div class=\"product_name\"><a href=\"$product_link\" target=\"_blank\" onclick=\"counts($id);\" > $name </a> </div>
	    <div>
	        <span class=\"price_left\">市场价:<span class=\"prime_price\">${prime_price}元</span></span>&nbsp;&nbsp;
	        <span class=\"price_right\">优惠价:<span class=\"price\">${price}元</span></span>
	    </div>
	    <div class=\"p_button\">
	        <span class=\"love\"><span class=\"count\">$click_counts</span><span class=\"static\">人关注 </span> </span>
	        <a class=\"buy\" href=\"$product_link\" target=\"_blank\" onclick=\"counts($id);\" ><img src=\"http://img04.taobaocdn.com/imgextra/i4/135326559/T24YckXmlXXXXXXXXX_!!135326559.gif\" alt=\"立即购买\"  /></a>
	    </div>
	    <div class=\"desc\"><p>$desc</p></div>
		</div>
	    ";
	}
}

